/*
============================================================================
 Name        : Playlist.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CPlaylist implementation
============================================================================
*/

#include "Playlist.h"
#include "PluginUtility.h"

TTrack::TTrack()
: iLocation(NULL), iTitle(NULL), iArtist(NULL), iAlbum(NULL), iImageUrl(NULL)
{
}

TTrack::~TTrack()
{
	DELETE(iLocation);
	DELETE(iTitle);
	DELETE(iArtist);
	DELETE(iAlbum);
	DELETE(iImageUrl);
}

const TDesC& TTrack::Location() const
{
	return *iLocation;
}

void TTrack::SetLocation(const TDesC& aLocation)
{
	DELETE(iLocation);
	iLocation = aLocation.Alloc();
}

const TDesC& TTrack::Title() const
{
	return *iTitle;
}

void TTrack::SetTitle(const TDesC& aTitle)
{
	DELETE(iTitle);
	iTitle = aTitle.Alloc();
}

const TDesC& TTrack::Artist() const
{
	return *iArtist;
}

void TTrack::SetArtist(const TDesC& aArtist)
{
	DELETE(iArtist);
	iArtist = aArtist.Alloc();
}

const TDesC& TTrack::Album() const
{
	return *iAlbum;
}

void TTrack::SetAlbum(const TDesC& aAlbum)
{
	DELETE(iAlbum);
	iAlbum = aAlbum.Alloc();
}

const TDesC& TTrack::ImageUrl() const
{
	return *iImageUrl;
}

void TTrack::SetImageUrl(const TDesC& aImageUrl)
{
	DELETE(iImageUrl);
	iImageUrl = aImageUrl.Alloc();
}

TPlaylist::TPlaylist()
: iTitle(NULL)
{
}

TPlaylist::~TPlaylist()
{
	iTracks.ResetAndDestroy();
}

const TDesC& TPlaylist::Title() const
{
	return iTitle;
}

void TPlaylist::SetTitle(const TDesC& aTitle)
{
	iTitle.Copy(aTitle);
	
	//We replace '+' for ' '
	TInt pos;
	while (ETrue)
	{
		pos = iTitle.Find(_L("+"));
		if (pos == KErrNotFound) break;
		iTitle.Replace(pos, 1, _L(" "));
	}
}

RPointerArray<TTrack> TPlaylist::Tracks()
{
	return iTracks;
}

void TPlaylist::AppendTrackL(TTrack* aTrack)
{
	iTracks.AppendL(aTrack);
}